﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;

namespace ERP.Hoadon
{
    public partial class viewERP_QL_Hangdu : DevExpress.XtraEditors.XtraForm
    {
        public cs_erp_hoadonInfo hoadon = new cs_erp_hoadonInfo();
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();
        public cs_erp_hanghoaInfo hanghoa = new cs_erp_hanghoaInfo();
        public cs_erp_khohangInfo kho = new cs_erp_khohangInfo();
        public cs_erp_nhapkhoInfo nk = new cs_erp_nhapkhoInfo();
        int count = 0;
        public int flag = 1;

        public viewERP_QL_Hangdu()
        {
            InitializeComponent();
        }

        private void viewERP_QL_Hangdu_Load(object sender, EventArgs e)
        {
            this.Load_Data();
            this.CheckUser();
        }
        private void CheckUser()
        {
            cs_hmr_userrightInfo userright = new cs_hmr_userrightInfo();
            userright.groupid = this.user.groupid;
            cs_hmr_winformInfo wf = new cs_hmr_winformInfo();
            wf.tenform = this.Name;
            if (wf.Get_Info() > 0)
            {
                userright.form_id = wf.formid;
                userright.Get_Info();
                if (userright.savedata == 0)
                {
                    
                }
                if (userright.deletedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.updatedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.printreport == 0)
                {
                }
            }
        }
        private void Load_Data()
        {
            DataSet ds = new DataSet("ds");
            ds = this.hanghoa.Get_List_Hangdu();
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                this.count = 0;
            }
            else
            {
                this.count = ds.Tables[0].Rows.Count;
                this.grcDanhsach.DataSource = ds.Tables[0];
                this.gridView1.ExpandAllGroups();
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            DialogResult dg = new DialogResult();
            dg = XtraMessageBox.Show("Bạn có chắc chắn muốn Hủy danh sách Hàng Thừa đã chọn?", "Cảnh báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dg == DialogResult.No)
            {
                return;
            }
            int k = 0;
            for (int i = 0; i < this.count; i++)
            {
                if (Convert.ToBoolean(this.gridView1.GetRowCellValue(i, gridColumn2).ToString().Trim()) == true)
                {
                    cs_erp_chitiet_nhapkhoInfo ct = new cs_erp_chitiet_nhapkhoInfo();

                    ct.id_chitiet_nhapkho = Convert.ToInt32(this.gridView1.GetRowCellValue(i, grdcID).ToString().Trim());

                    ct.Xoahangdu();
                }

            }
            XtraMessageBox.Show("Xóa thành công: " + k + " hàng thừa đã chọn!", "Thông báo");
            this.Load_Data();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose(true);
        }
    }
}